package com.edwin.websitebe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edwin.websitebe.mapper.KnowledgeMapper;
import com.edwin.websitebe.model.Knowledge;
import com.edwin.websitebe.model.News;
import com.edwin.websitebe.model.Sample;
import com.edwin.websitebe.service.KnowledgeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class KnowledgeServiceImpl extends ServiceImpl<KnowledgeMapper, Knowledge> implements KnowledgeService {

    @Override
    public Page<Knowledge> pageList(Knowledge knowledge) {
        LambdaQueryWrapper<Knowledge> wrapper = new QueryWrapper<Knowledge>().lambda()
                .like(StringUtils.isNotEmpty(knowledge.getKnowledgeTitle()), Knowledge::getKnowledgeTitle, knowledge.getKnowledgeTitle())
                .orderByAsc(Knowledge::getSort)
                .orderByDesc(Knowledge::getCreateTime);
        return this.page(Page.of(knowledge.getPage(), knowledge.getPageSize()), wrapper);
    }

}
